package com.grass.appointment.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.utils.ImageUtil;
import com.grass.appointment.C2694R;
import java.util.ArrayList;
import java.util.List;

public class SendImageAdapter extends BaseAdapter {
    private Context context;
    private List<String> imageList = new ArrayList();
    private View.OnClickListener onClickListener;

    public void setOnClickListener(View.OnClickListener onClickListener2) {
        this.onClickListener = onClickListener2;
    }

    public void setImageList(List<String> list) {
        this.imageList = list;
        notifyDataSetChanged();
    }

    public SendImageAdapter(Context context2) {
        this.context = context2;
    }

    public int getCount() {
        List<String> list = this.imageList;
        if (list == null) {
            return 0;
        }
        return list.size();
    }

    public Object getItem(int i) {
        List<String> list = this.imageList;
        if (list == null) {
            return null;
        }
        return list.get(i);
    }

    public long getItemId(int i) {
        if (this.imageList == null) {
            return 0;
        }
        return (long) i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = View.inflate(this.context, C2694R.C2699layout.item_grid_image, null);
            viewHolder = new ViewHolder();
            viewHolder.ivImage = (ImageView) view.findViewById(C2694R.C2697id.iv_img);
            viewHolder.btnIvDelete = (ImageView) view.findViewById(C2694R.C2697id.btn_iv_delete);
            viewHolder.btnIvDelete.setOnClickListener(this.onClickListener);
            viewHolder.btnIvDelete.setTag(Integer.valueOf(i));
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (this.imageList.get(i).equals(Key.ADD_IMAGE)) {
            GlideUtils.loadResId(ImageUtil.getResource(this.imageList.get(i)), viewHolder.ivImage);
            viewHolder.btnIvDelete.setVisibility(8);
        } else {
            GlideUtils.loadPic(this.imageList.get(i), viewHolder.ivImage);
            viewHolder.btnIvDelete.setVisibility(0);
        }
        return view;
    }

    static class ViewHolder {
        ImageView btnIvDelete;
        ImageView ivImage;

        ViewHolder() {
        }
    }
}
